<template>
  <div style="padding: 20px">
    <el-table
      v-loading="loading"
      :data="softwareHistoryList"
      @selection-change="handleSelectionChange"
      :row-class-name="tableRowClassName"
    >
      <el-table-column
        label="软件名称"
        align="center"
        prop="historyName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="软件制作时间"
        align="center"
        prop="historyCreateTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.historyCreateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="软件制作人"
        align="center"
        prop="historyCreater"
        width="180"
      />
      <el-table-column
        label="版本"
        align="center"
        prop="historyVersion"
        width="180"
      />
      <el-table-column
        label="是否当前使用版本"
        align="center"
        prop="isMaster"
        width="180"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isMaster == '1'" type="success">是</el-tag>
          <el-tag v-else type="primary">否</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:dict:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
            >查看</el-button
          >
          <el-button
            v-hasPermi="['system:dict:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <history-detail ref="historyDetail"></history-detail>
  </div>
</template>

<script>
import HistoryDetail from "./detail.vue";
import {
  listHistory,
  deleteHistoryById,
} from "@/api/resource/software-history.js";
export default {
  components: { HistoryDetail },
  data() {
    return {
      loading: false,
      softwareHistoryList: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      let param = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        softwareId: this.$route.params.id,
      };
      listHistory(param).then((res) => {
        this.softwareHistoryList = res.rows;
        this.total = res.total;
      });
    },
    handleCheck(row) {
      this.$refs.historyDetail.historyOpen(row);
    },
    handleDelete(row) {
      if (this.total == 1) {
        this.$message.warning("不可删除唯一版本");
        return;
      }
      if (row.isMaster == "1") {
        this.$message.warning("此版本为当前使用版本，不可删除");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteHistoryById(row.id).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-table .success-row {
  background: #f0f9eb;
}
</style>
